<!DOCTYPE html>
<html>
	{include file="public/_header" /}
	<!-- 配置文件 -->
	<script type="text/javascript" src="__STATIC__/static/ueditor/ueditor.config.js"></script>
	<!-- 编辑器源码文件 -->
	<script type="text/javascript" src="__STATIC__/static/ueditor/ueditor.all.js"></script>
	<style type="text/css">
		.layui-input,
		.layui-select,
		.layui-textarea {
			height: 32px;
			line-height: 1;
		}
	</style>
	<body>
		<div class="layui-fluid">
		  <div class="layui-row layui-col-space15">
		    <div class="layui-col-md12">
		      <div class="layui-card">
		        <div class="layui-card-body">
		          <form class="layui-form" action="">
		          		<div class="layui-form-item">
		          			<label class="layui-form-label">通知标题</label>
		          			<div class="layui-input-block">
		          				<input type="text" name="name" required lay-verify="required" autocomplete="off" class="layui-input title">
		          			</div>
		          		</div>
		          		<div class="layui-form-item">
		          			<label class="layui-form-label">开始时间</label>
		          			<div class="layui-input-block">
								 <input type="text" id="start_time" name="start_time" required lay-verify="datetime" placeholder="yyyy-MM-dd HH:mm:ss"
								  autocomplete="off" class="layui-input">
		          			</div>
		          		</div>
		          		<div class="layui-form-item">
		          			<label class="layui-form-label">结束时间</label>
		          			<div class="layui-input-block">
								 <input type="text" id="end_time" name="end_time" required lay-verify="datetime" placeholder="yyyy-MM-dd HH:mm:ss"
								  autocomplete="off" class="layui-input">
		          			</div>
		          		</div>
		          		<div class="layui-form-item layui-form-text">
		          			<label class="layui-form-label">通知内容</label>
		          			<div class="layui-input-block">
								 <textarea id="content" name="content" style="height: 300px;width:100%"></textarea>
		          			</div>
		          		</div>
						<script>
							var ue = UE.getEditor('content');
						</script>
						<div class="layui-form-item layui-form-text">
							<label class="layui-form-label">内容摘要</label>
							<div class="layui-input-block">
								 <textarea id="description" name="description" class="layui-textarea"></textarea>
							</div>
						</div>
		          		<div class="layui-form-item">
		          			<label class="layui-form-label">显示</label>
		          			<div class="layui-input-block">
		          				<input type="checkbox" id="status" name="status" lay-filter="switchTest" lay-skin="switch" lay-text="显示|隐藏" checked>
		          			</div>
		          		</div>
		          		<div class="layui-form-item">
		          			<label class="layui-form-label">置顶</label>
		          			<div class="layui-input-block">
		          				<input type="checkbox" id="ispage" name="ispage" lay-filter="switchTest" lay-skin="switch" lay-text="是|否">
		          			</div>
		          		</div>
		          		<div class="layui-form-item">
		          			<div class="layui-input-block">
		          				<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
		          				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
		          			</div>
		          		</div>
		          	</form>
		          
		        </div>
		      </div>
		    </div>
		  </div>
		</div>
	</body>
	<script type="text/javascript">
		layui.use(['form', 'upload','laydate'], function() {
			var form = layui.form;
			var $ = layui.jquery;
			var laydate = layui.laydate;
			form.verify({
			  varVerify: function(value, item){ //value：表单的值、item：表单的DOM对象
			    if(!new RegExp("^[a-zA-Z]([-_a-zA-Z0-9]{3,20})$").test(value)){
			      return '必须以字母开头的3-20位英文字符串';
			    }
			  }
			});
			
			laydate.render({
				elem: '#start_time',
				type: 'datetime',
				format: 'yyyy-MM-dd HH:mm:ss'
			});
			laydate.render({
				elem: '#end_time',
				type: 'datetime',
				format: 'yyyy-MM-dd HH:mm:ss'
			});
			//监听提交
			form.on('submit(formDemo)', function(obj) {
				if (obj.field.status) {
					obj.field.status = 1
				} else {
					obj.field.status = 0
				}
				if (obj.field.ispage) {
					obj.field.ispage = 1
				} else {
					obj.field.ispage = 0
				}
				var index = parent.layer.getFrameIndex(window.name);
				var lfc = top.layerFrameConfig;
				var info = lfc.iframeB.info;
				console.log(obj.field)
				$.post("{:url('admin/Mould/add')}", obj.field, function(res) {
					if (res.status == 1) {
						layer.msg('添加成功', {
							icon: 1,
							time: 300
						}, function() {
							parent.layer.close(index); //再执行关闭
							info.reload()
						});
		
					} else {
						layer.msg(res.message)
					}
				})
				return false;
			});
		});
	</script>
</html>
